Page({
  data: {
    pageIndex: 0,
    PageSize: 20,
    key: "",
    noMore: false,
    customerList: [],
    currenti: null,
    currentj: null,
    startX: 0
  },
  onLoad() {
    this.getlist()
  },
  getlist() {
    var _this = this
    console.log(this.data.pageIndex);
    
    if(!this.data.noMore){
      dd.showLoading({
        content: '加载中...',
      });
      getApp().req({
        url: "/customer/channelcustomerlist",
        data: {
          pageIndex: _this.data.pageIndex+1,
          PageSize: _this.data.PageSize,
          key: _this.data.key
        },
        cb(res){

          console.log(res)
          for (const i in res.data) {
            for (const j in res.data[i].CustomerDemands.Items) {
              res.data[i].CustomerDemands.Items[j].x = 0
              res.data[i].CustomerDemands.Items[j].y = 0
            }
          }
          if(res.data.length == _this.data.PageSize){

          }else{
            _this.setData({noMore: true})
          }
          if(_this.data.pageIndex == 0){
            var newlist = res.data
          }else{
            var newlist = _this.data.customerList.concat(res.data)
          }
          _this.setData({
            pageIndex:_this.data.pageIndex+1,
            customerList:newlist
            })
        },
        fail(){
          _this.setData({noMore: true})
          console.log(_this.data.noMore);
          
        },
        complete() {
          dd.hideLoading();
          dd.stopPullDownRefresh()
        }
      })
    }else{
      dd.showToast({
        content: '没有更多',
        duration: 1500
      });
    }
  },
  addmore() {
    console.log("low")
  },
  toEdit(e) {
    console.log(e)

    
    // dd.navigateTo({
    //  url:"../crmchannel/crmchanneldetail?id="+e.target.dataset.did
    // })
  },
  toDetail(e) {

    console.log(e);
    dd.navigateTo({
      url:"../crmchanneldetail/crmchanneldetail?id="+e.target.dataset.did
    })
  },
  moveStart(e) {
    // console.log("moveStart");
    // console.log(e);
    var list = this.data.customerList
    if(this.data.currenti == e.target.dataset.i && this.data.currentj == e.target.dataset.j){

    }else{
      // console.log("re");
      
      for (const i in list) {
        for (const j in list[i].CustomerDemands.Items) {
          list[i].CustomerDemands.Items[j].x = 0
          list[i].CustomerDemands.Items[j].y = 0
        }
      }
      list[e.target.dataset.i].CustomerDemands.Items[e.target.dataset.j].x = -1
      this.setData({
        customerList: list,
        currenti: e.target.dataset.i,
        currentj: e.target.dataset.j
        })
    }
    this.setData({
      startX:e.changedTouches[0].clientX
    })

  },
  moveend(e) {
    var list = this.data.customerList
    var x = e.changedTouches[0].clientX - this.data.startX
    var random = Math.random()*-1
    // if(x<-50){
    //   list[e.target.dataset.i].CustomerDemands.Items[e.target.dataset.j].x = -100+random
    // }else{
    //   list[e.target.dataset.i].CustomerDemands.Items[e.target.dataset.j].x = 0
    // }
    this.setData({customerList:list})
    
  },
  onTitleClick() {
    // 标题被点击
  },
  onPullDownRefresh() {
    // 页面被下拉
    var _this = this
    this.setData({
      pageIndex:0,
      noMore:false
      })
    this.getlist()
  },
  onReachBottom() {
    // 页面被拉到底部
    this.getlist()
  },
});
